//
//  UIApplication+Extension.m
//  OMTCoreKit
//
//  Created by 昭荣伊 on 2018/7/27.
//

#import "UIApplication+Extension.h"



@implementation UIApplication (Extension)
- (NSString *)omt_version {
    NSString * value = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    return value;
}

- (NSString *)omt_buildVersion {
    NSString *buildVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
    return buildVersion;
}

- (NSString *)omt_bundleId {
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
}

- (NSString *)omt_currentLanguage {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    
    NSString *currentLanguage = [languages objectAtIndex:0];
    if (currentLanguage.length > 2) {
        currentLanguage = [currentLanguage substringToIndex:2];
    }
    return currentLanguage;
}

- (NSString *)omt_countryCode {
    NSString *countryCode = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
    return  countryCode;
}

- (BOOL)omt_rightToLeftLanguage {
    return [self omt_isRightToLeftLanguage:self.omt_currentLanguage];
}

- (BOOL)omt_isRightToLeftLanguage:(NSString *)language {
    if (language.length > 2) {
        language = [language substringToIndex:2];
    }
    if (language.length < 2) {
        return NO;
    }
    
    NSArray *rightToLeftLanguages = @[@"ar", @"fa"];
    for (NSString *string in rightToLeftLanguages) {
        if ([language containsString:string]) {
            return YES;
        }
        continue;
    }
    return NO;
}

@end
